package com.hyh.admin.controller.resources;

import com.hyh.ad.common.core.controller.BaseController;
import com.hyh.ad.common.core.domain.AjaxResult;
import com.hyh.ad.common.utils.SecurityUtils;
import com.hyh.admin.domain.resources.ResourcesDanmu;
import com.hyh.admin.domain.resources.ResourcesViews;
import com.hyh.admin.service.IResourcesDanmuService;
import com.hyh.admin.service.IResourcesViewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/resources/views")
@Api(tags = "资源浏览历史记录管理")
public class ResourcesViewsController extends BaseController {
    @Autowired
    private IResourcesViewsService resourcesViewsService;


    /*
     * 添加资源浏览历史记录
     */
    @PostMapping("/insert")
    @ApiOperation(value = "添加资源浏览历史记录")
    public AjaxResult insert(@RequestBody ResourcesViews resourcesViews) {
        resourcesViews.setUserId(SecurityUtils.getLoginUser().getUser().getId());
        return toAjax(resourcesViewsService.insertResourcesViews(resourcesViews));
    }

    /*
     * 删除资源浏览历史记录
     */
    @DeleteMapping("/delete/{resourceId}")
    @ApiOperation(value = "删除资源浏览历史记录")
    public AjaxResult delete(@PathVariable Long resourceId) {
        return toAjax(resourcesViewsService.deleteResourcesViews(resourceId));
    }

    /*
     * 查询资源浏览历史记录
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询资源浏览历史记录")
    public AjaxResult list() {
        return AjaxResult.success(resourcesViewsService.selectResourcesViewsByUserId(SecurityUtils.getLoginUser().getUser().getId()));
    }
}
